package aViewLayer;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import aModelLayer.Menu;
import aaGame.RpgGamePanel;

public class TitleView extends View {

	Menu mMenu;
	private BufferedImage titleScreen;
	private BufferedImage menuArrow;
	private int alpha;
	
	public TitleView(Menu menu){
		mMenu = menu; 
		alpha=0;
		/* Initializes the images for the title screen and menu arrow. */
		try {
			titleScreen = ImageIO.read(new File(this.getClass()
					.getResource("/images/titleScreen.png").toURI()));
			menuArrow = ImageIO.read(new File(this.getClass()
					.getResource("/images/menuArrow.png").toURI()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void render(Graphics2D g, RpgGamePanel root) {
		// TODO Auto-generated method stub
		/* Draws the title screen */
		g.drawImage(titleScreen, (root.getWidth() / 2)
				- (RpgGamePanel.PANEL_WIDTH / 2), (root.getHeight() / 2)
				- (RpgGamePanel.PANEL_HEIGHT / 2), null);

		/*
		 * Draws the menu arrow in a certain position depending on which menu
		 * item is currently selected.
		 */
		if (mMenu.isSelected()){
			if (alpha<=253)
				alpha += 3;
			g.setColor(new Color(0, 0, 0, alpha));
			g.fillRect(0, 0, root.getWidth(), root.getHeight());
		}
		else {	
			mMenu.reset();
			alpha = 0;
			switch (mMenu.getCurrentOption()) {
			case "Start New Game":
				g.drawImage(menuArrow, (root.getWidth() / 2) - 226,
						(root.getHeight() / 2) + 5, null);
				break;
			case "Load Game":
				g.drawImage(menuArrow, (root.getWidth() / 2) - 226,
						(root.getHeight() / 2) + 59, null);
				break;
			case "Exit":
				g.drawImage(menuArrow, (root.getWidth() / 2) - 226,
						(root.getHeight() / 2) + 115, null);
				break;
			}
		}
	}


}
